import { _decorator, Button, Label } from 'cc';
import { BasePopUp } from '../../../frame/component/ui.pop-up';
import Config from '../../manager/config.manager';
import GameAssets from '../../manager/game.assets';
import type { Popup } from '../page/popup';
const { ccclass, property } = _decorator;

@ccclass('FreeSuccess')
export class FreeSuccess extends BasePopUp<typeof Popup, null> {
	protected default_return: null;

	private lbl_symbol: Label;

	protected initAfterOnLoad(): void {
		this.lbl_symbol = this.node.getChildByName('lbl-symbol').getComponent(Label);

		this.renderLocalUI();
	}

	public onShow(symbol: number): void {
		this.lbl_symbol.string = Config.symbolString(symbol);

		BasePopUp.jelly_enter(this.node);
	}

	protected _click_event_: { [name: string]: (this: FreeSuccess, button: Button) => void; } = {
		close(btn){
			btn.interactable = false;
			BasePopUp.jelly_leave(this.node).then(()=>{
				this.close(null);
				btn.interactable = true;
			});
		}
	}

	private renderLocalUI(): void {
		(<const>[
			['head', GameAssets.getLangText(77)],
			['desc', GameAssets.getLangText(78)]
		]).forEach(([name, text])=>{
			this.node.getChildByName('lbl-'+name).getComponent(Label).string = text;
		});
	}
}

